﻿using System;
using Rebazza.RegexGame.Entities;
using Rebazza.Server;
using Rebazza.Server.Entities;
using Rebazza.Utils.Constants;

namespace Rebazza.RegexGame
{
    class Program
    {
        private const int ROOM_COUNT = 100;

        static void Main(string[] args)
        {
            var server = new GameServer(PortConstants.Regex, ROOM_COUNT);
            ListenServer(server);
            server.Start();
            var command = string.Empty;
            while (command != "exit")
            {
                command = Console.ReadLine();
            }

            UnsubscribeFromTheServer(server);
            server.Stop();
        }

        private static void CheckCommand(string command)
        {
        }
            
        private static void ListenServer(BaseGameServer server)
        {
            server.ClientConnected += OnClientConnected;
            server.ClientDisconnected += OnClientDisconnected;
        }

        private static void UnsubscribeFromTheServer(BaseGameServer server)
        {
            server.ClientConnected -= OnClientConnected;
            server.ClientDisconnected -= OnClientDisconnected;
        }

        public static void OnClientConnected(object sender, ServerEventArgs e)
        {
            Console.WriteLine("{0}[{1}]: connected", e.User.Login, e.User.Context.ClientAddress);
        }

        public static void OnReceiveFromClient(object sender, ServerEventArgs e)
        {
            Console.WriteLine("{0}[{1}]: send message", e.User.Login, e.User.Context.ClientAddress);

        }

        public static void OnSendToClient(object sender, ServerEventArgs e)
        {
            
        }

        public static void OnClientDisconnected(object sender, ServerEventArgs e)
        {
            Console.WriteLine("{0}[{1}]: disconnected", e.User.Login, e.User.Context.ClientAddress);
        }
    }
}
